/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SubmeteDocumentos.java
 *
 * Created on 28/10/2010, 19:55:29
 */

package Janelas;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import submissao.ConexaoBD;
import submissao.Participante;
import submissao.Trabalho;

/**
 *
 * @author Vitor
 */
public class SubmeteDocumentos extends javax.swing.JFrame {

    /** Creates new form SubmeteDocumentos */
    public SubmeteDocumentos(ConexaoBD conexao) {
        this.conexao = conexao;

        initComponents();
        this.setTitle("Submeter Documento");
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
	int alturaTela = d.height;
	int comprimentoTela = d.width;
	setLocation((comprimentoTela)/4, (alturaTela)/8);
        this.setResizable(false);
        this.setDefaultCloseOperation(HIDE_ON_CLOSE);
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        tTitulo = new javax.swing.JTextField();
        tPalavra = new javax.swing.JTextField();
        tPrincipal = new javax.swing.JTextField();
        tArea = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        aResumo = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        aConteudo = new javax.swing.JTextArea();
        tOutros = new javax.swing.JTextField();
        bSubmete = new javax.swing.JButton();
        bCancela = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel2.setText("Titulo:");

        jLabel4.setText("Área de Pesquisa:");

        jLabel5.setText("Autor Principal:");

        jLabel6.setText("Outros Autores:");

        jLabel7.setText("Conteúdo:");

        jLabel8.setText("Resumo:");

        jLabel9.setText("Palavras-chave:");

        aResumo.setColumns(20);
        aResumo.setRows(5);
        jScrollPane1.setViewportView(aResumo);

        aConteudo.setColumns(20);
        aConteudo.setRows(5);
        jScrollPane2.setViewportView(aConteudo);

        bSubmete.setText("Submter");
        bSubmete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bSubmeteActionPerformed(evt);
            }
        });

        bCancela.setText("Cancelar");
        bCancela.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                bCancelaMouseClicked(evt);
            }
        });
        bCancela.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bCancelaActionPerformed(evt);
            }
        });

        jLabel1.setForeground(new java.awt.Color(255, 0, 0));
        jLabel1.setText("*");

        jLabel3.setForeground(new java.awt.Color(255, 0, 0));
        jLabel3.setText("*");

        jLabel10.setForeground(new java.awt.Color(255, 0, 0));
        jLabel10.setText("*");

        jLabel11.setForeground(new java.awt.Color(255, 0, 0));
        jLabel11.setText("*");

        jLabel12.setForeground(new java.awt.Color(255, 0, 0));
        jLabel12.setText("campos obrigatórios.");

        jLabel13.setForeground(new java.awt.Color(255, 0, 0));
        jLabel13.setText("*");

        jLabel14.setForeground(new java.awt.Color(255, 0, 0));
        jLabel14.setText("*");

        jLabel15.setForeground(new java.awt.Color(255, 0, 0));
        jLabel15.setText("*");

        jLabel16.setText("colocar o campo para categoria");

        jLabel17.setText("informar ao usuário como os campos devem ter o formato, aqui tem que ter ',' para + de 1 palavra chave");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel16)
                        .addGap(416, 416, 416))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel17)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
                        .addGap(426, 426, 426))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 510, Short.MAX_VALUE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(tPalavra, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(tPrincipal, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(tOutros, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(tArea, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 457, Short.MAX_VALUE)
                        .addComponent(tTitulo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 492, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(jLabel11)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabel12)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(bSubmete)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(bCancela)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 510, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 171, Short.MAX_VALUE)
                        .addGap(431, 431, 431)))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel4, jLabel6, jLabel8, jLabel9});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {bCancela, bSubmete});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1)
                    .addComponent(jLabel16))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel13)
                    .addComponent(jLabel17))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tPalavra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tOutros, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel15))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12)
                    .addComponent(bSubmete)
                    .addComponent(bCancela))
                .addGap(44, 44, 44))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bSubmeteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bSubmeteActionPerformed
        // TODO add your handling code here:
        String titulo;
        String palavrasChave;
        String autorPrincipal;
        String outrosAutores;
        String areaPesquisa;
        String resumo;
        String conteudo;
        
        // pegar a categoria da interface e substituir nesta variavel
        String categoria = "1";

        titulo = tTitulo.getText();
        // Valter : Villela, não esqueça de informar na interface que para mais de uma palavra chave, deve ter o limitador ',' blz?
        palavrasChave = tPalavra.getText();
        autorPrincipal = tPrincipal.getText();
        outrosAutores = tOutros.getText();
        areaPesquisa = tArea.getText();
        resumo = aResumo.getText();
        conteudo = aConteudo.getText();

        String[] arrayPalavra = palavrasChave.split(",");
        ArrayList<String> aPalavraChave = new ArrayList<String>();

        for(int i =0; i < arrayPalavra.length; i++){
            aPalavraChave.add(arrayPalavra[i]);
        }

        Trabalho trabalho = new Trabalho(titulo, aPalavraChave, autorPrincipal, outrosAutores, areaPesquisa, resumo, conteudo, Integer.parseInt(categoria));
        conexao.cadastrarTrabalho(trabalho);
        

        /*
        if(titulo.equals("")){
            JOptionPane.showMessageDialog(this,"Campo Título não pode ficar em branco","Erro na entrada de Dados",JOptionPane.INFORMATION_MESSAGE);
        }
        if(palavrasChave.equals("")){
            JOptionPane.showMessageDialog(this,"Campo Palavra-chave não pode ficar em branco","Erro na entrada de Dados",JOptionPane.INFORMATION_MESSAGE);
        }
        if(autorPrincipal.equals("")){
            JOptionPane.showMessageDialog(this,"Campo Autor Principal não pode ficar em branco","Erro na entrada de Dados",JOptionPane.INFORMATION_MESSAGE);
        }
        if(areaPesquisa.equals("")){
            JOptionPane.showMessageDialog(this,"Campo Área de Pesquisa não pode ficar em branco","Erro na entrada de Dados",JOptionPane.INFORMATION_MESSAGE);
        }
        if(resumo.equals("")){
            JOptionPane.showMessageDialog(this,"Campo Resumo não pode ficar em branco","Erro na entrada de Dados",JOptionPane.INFORMATION_MESSAGE);
        }
        if(conteudo.equals("")){
            JOptionPane.showMessageDialog(this,"Campo Conteudo não pode ficar em branco","Erro na entrada de Dados",JOptionPane.INFORMATION_MESSAGE);
        }
        */
    }//GEN-LAST:event_bSubmeteActionPerformed

    private void bCancelaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bCancelaActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_bCancelaActionPerformed

    private void bCancelaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_bCancelaMouseClicked
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_bCancelaMouseClicked

    /**
    * @param args the command line arguments
    */
    /*
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SubmeteDocumentos().setVisible(true);
            }
        });
    }
    */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea aConteudo;
    private javax.swing.JTextArea aResumo;
    private javax.swing.JButton bCancela;
    private javax.swing.JButton bSubmete;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField tArea;
    private javax.swing.JTextField tOutros;
    private javax.swing.JTextField tPalavra;
    private javax.swing.JTextField tPrincipal;
    private javax.swing.JTextField tTitulo;
    // End of variables declaration//GEN-END:variables
    private ConexaoBD conexao;
}
